package com.allen.mapper;

import com.allen.bean.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: allen
 * @Data: 2021.06.18.20:34
 **/
@Mapper //标记mapper文件位置，否则在Application.class启动类上配置mapper包扫描
@Repository
public interface CommentMapper {

    /**
     * 提交评论
     * @return
     */
    @Insert(value="insert into comments values(#{c_id},#{w_username},#{w_font},#{c_username},#{c_font},#{c_day},#{c_yymm},#{c_ias})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void subc(Comment comment);

    /**
     * 查询评论
     */
    @Select(value="select*from comments where w_username=#{w_username}&&w_font=#{w_font}")
//    @Select(value="select*from myworks where username=#{username}")
    @Results
            ({@Result(property = "w_username",column = "w_username"),
                @Result(property = "w_font",column = "w_font")})    //@Result：为了解决数据库字段名与实体类属性名不一致的问题,//column:数据库字段名，property：实体类属性名
    List<Comment> selc(Comment comment);

}
